package bhbt.service.log;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import bhbt.model.Admin;
import bhbt.model.Member;
import bhbt.model.log.LogShui;
import bhbt.model.log.LogShuiTi;
import bhbt.service.MemberService;
import bhbt.service.core.BaseService;
import bhbt.utils.ContextUtil;
import bhbt.utils.StringUtil;






@Service
public class LogShuiTiService extends BaseService {
	
	
	@Resource
    private MemberService memberService;
	@Resource
    private LogShuiTiService logShuiTiService;
	@Resource
    private LogShuiService logShuiService;
	
	/**
	 * 保存
	 * @param member
	 */
	public void saveTi(LogShuiTi logShuiTi){
		
		//新增记录
		logShuiTiService.saveOrUpdate(logShuiTi);
		
		
		Member member = ContextUtil.getMember();
		member= memberService.getByKey(member.getId());
		
		
		Double num = logShuiTi.getNum()+logShuiTi.getFei();
		
		Map mapMember = new HashMap();
		mapMember.put("id",member.getId());
		mapMember.put("diyUpdate","Shui=Shui-"+num);
        //更新余额 
        memberService.update(mapMember);
        
         
        member= memberService.getByKey(member.getId());
        Double yu = member.getShui();
        
        
        //新增记录
        LogShui logShui = new LogShui();
        logShui.setMemberId(member.getId());
        logShui.setTitle("电子币提现，提现金额："+logShuiTi.getNum()+",手续费："+logShuiTi.getFei());
        logShui.setState(88);      
        logShui.setNum(-num);
        logShui.setYu(yu);      
        logShuiService.saveOrUpdate(logShui);
		 
		 
	}
	
	/**
	 * 取消
	 * @param member
	 */
	public void updateCancel(Integer id){
		
		//更新状态
		Map mapLogShuiTi = new HashMap();
		mapLogShuiTi.put("id",id);
		mapLogShuiTi.put("state",30);
		mapLogShuiTi.put("commitDate",new Date());
    	logShuiTiService.update(mapLogShuiTi);
    	
    	
    	
    	LogShuiTi logShuiTi = logShuiTiService.getByKey(id); 
    	Member member= memberService.getByKey(logShuiTi.getMemberId());		
		
		Double num = logShuiTi.getNum()+logShuiTi.getFei();
		
		Map mapMember = new HashMap();
		mapMember.put("id",member.getId());
		mapMember.put("diyUpdate","Shui=Shui+"+num);
        //更新余额 
        memberService.update(mapMember);
        

        member= memberService.getByKey(member.getId());
        Double yu = member.getShui();
        
        
        
        //新增记录
        LogShui logShui = new LogShui();
        logShui.setMemberId(member.getId());
        logShui.setTitle("电子币提现取消，提现金额："+logShuiTi.getNum()+",手续费："+logShuiTi.getFei());
        logShui.setState(88);       
        logShui.setNum(-num);
        logShui.setYu(yu);      
        logShuiService.saveOrUpdate(logShui);
	}

}
